var bol = 0;
var iptAct = document.querySelectorAll('.ipt.act')
var selBox = document.querySelectorAll('.box')
var selBoxItem1 = document.querySelectorAll('#box1 .item')
var selBoxItem2 = document.querySelectorAll('#box2 .item')
var selBoxItem3 = document.querySelectorAll('#box3 .item')
var nameDat = document.getElementById("nameDat"),
  nameDatTitle = document.querySelector("#nameDat .top-title"),
  nameDatIpt = document.querySelector("#nameDat input")
function handClickIpt(elem1, elem2) {
  elem1.addEventListener('click', function () {
    var _this = this;
    if(bol == 0) {
      _this.style = "border-radius: 5px 5px 0 0;border-bottom: 0;"
      elem2.style.display = "block"
      bol = 1
    }else {
      _this.style = ""
      elem2.style.display = "none"
      bol = 0
    }
  });
}
handClickIpt(iptAct[0], selBox[0])
handClickIpt(iptAct[1], selBox[1])
handClickIpt(iptAct[2], selBox[2])
function handClickSel(elem1, elem2, elem3, iptCont, bole, sonSel) {
  for (var i = 0; i < elem1.length; i++) {
    elem1[i].addEventListener('click', function () {
      var _this = this
      iptCont.val(this.innerText)
      elem2.innerHTML = this.innerText + "<span></span>"
      elem2.style = ""
      elem3.style.display = "none"
      bol = 0
      if (bole == 1) {
        if (this.innerText.indexOf('企业') != -1) {
          nameDatTitle.innerHTML = "<i class=\"act\">*</i>单位名称"
          nameDatIpt.placeholder = "请填写单位名称"
          $("#invoice").css('display', 'none')
          $("input[name='unit']").val('')
        } else {
          nameDatTitle.innerHTML = "<i class=\"act\">*</i>真实姓名"
          nameDatIpt.placeholder = "请填写您的真实姓名"
          $("#invoice").css('display', 'block')
        }
        nameDat.style.display = "block"
      }
      if (sonSel) {
        if (this.innerText == "学校榜") {
          $(".ipt-div").css('display', 'block')
          $(".ipt-div input").attr("placeholder", "请填写学校的名称")
          elem2.style = " border-radius: 5px 5px 0 0 !important;border-bottom: 0;"
        }else if (this.innerText == "粉丝榜") {
          $(".ipt-div").css('display', 'block')
          $(".ipt-div input").attr("placeholder", "请填写爱豆名称")
          elem2.style = " border-radius: 5px 5px 0 0 !important;border-bottom: 0;"
        } else if (this.innerText == "家庭榜") {
          $(".ipt-div").css('display', 'block')
          $(".ipt-div input").attr("placeholder", "请填写家庭的名称")
          elem2.style = " border-radius: 5px 5px 0 0 !important;border-bottom: 0;"
        } else {
          $(".ipt-div").css('display', 'none')
          elem2.style = ""
        }
      }
    });
  }
}
handClickSel(selBoxItem1, iptAct[0], selBox[0], $("input[name='gongm']"), 1)
handClickSel(selBoxItem2, iptAct[1], selBox[1], $("input[name='fpType']"), 0, true)
handClickSel(selBoxItem3, iptAct[2], selBox[2], $("input[name='dbVal']"), 0)
// 金额部分
var lab = document.querySelectorAll('.label')
var labI = document.querySelectorAll('.label i')
for (var i = 0; i < lab.length; i++) {
  lab[i].index = i
  lab[i].addEventListener('click', function () {
    var _this = this;
    for (var j = 0; j < lab.length; j++) {
      lab[j].classList.remove('active')
      $("input[name='jine']").val(labI[_this.index].innerHTML)
    }
    this.classList.add('active')
  });
}


var iptBoxMust = document.querySelectorAll(".ipt-box.act")
var iptBoxMustIpt = document.querySelectorAll(".ipt-box.act input")
var fpTopBol = 0;
$(".fp-top span").click(function () {
  if(fpTopBol == 0) {
    $(".fp-top").addClass('act');
    fpTopBol = 1
    $(".fp-box").addClass('act');
    $(".fp-box .ipt-box").addClass('act')
    iptBoxMust = document.querySelectorAll(".ipt-box.act")
    iptBoxMustIpt = document.querySelectorAll(".ipt-box.act input")
  }else {
    $(".fp-top").removeClass('act');
    fpTopBol = 0
    $(".fp-box").removeClass('act');
    $(".fp-box .ipt-box").removeClass('act')
    iptBoxMust = document.querySelectorAll(".ipt-box.act")
    iptBoxMustIpt = document.querySelectorAll(".ipt-box.act input")
  }
});


$(".ipt-box.act input:eq(2)").focus(function(){
  for (var j = 0; j < lab.length; j++) {
    lab[j].classList.remove('active')
  }
});
$(".btn-submit").click(function () {
  if($("#city").text().indexOf("请选择省份") != -1) {
    alert("请选择省份")
    return false
  }
  for (var i = 0;i<iptBoxMust.length;i++) {
    if (iptBoxMustIpt[i].value == "") {
      alert(iptBoxMustIpt[i].placeholder)
      iptBoxMustIpt[i].focus()
      return false
    }
  }
  console.log(($("form").serialize()))
})

